package com.xujianlun.cpms.exception;

import com.xujianlun.cpms.common.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class HandlerException {
    @ExceptionHandler
    public Response<String> handleServiceException(ServiceException e) {
        log.info("**************IServiceException**************");
        log.info("【业务异常】：{}",e.getMessage(),e);
        return Response.error(e.getCode(),e.getMessage());
    }

    @ExceptionHandler
    public Response<String> handleRuntimeException(RuntimeException e){
        log.info("**************RuntimeException**************");
        log.info("【运行异常】：{}",e.getMessage(),e);
        return Response.error("运行异常");
    }

    @ExceptionHandler
    public Response<String> handleException(Exception e){
        log.info("【系统异常】：{}",e.getMessage(),e);
        return Response.error("系统异常");
    }
}
